package xiangmu.schoolpaper.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xiangmu.schoolpaper.mapper.PersonalCenterMapper;
import xiangmu.schoolpaper.pojo.DTO.UpdatePasswordDTO;
import xiangmu.schoolpaper.pojo.VO.PersonalCenterVO;
import xiangmu.schoolpaper.result.Result;
import xiangmu.schoolpaper.service.PersonalCenterService;
import xiangmu.schoolpaper.service.impl.PersonalCenterServiceImpl;
import xiangmu.schoolpaper.service.impl.UserServiceImpl;

@RestController
@RequestMapping("/PersonalCenter")
@Slf4j
@Tag(name="个人中心接口")
public class PersonalCenterController {
    @Autowired
    private PersonalCenterService personalCenterService;

    @GetMapping("/getUserInfoByAccount")
    @Operation(summary = "根据账号获取用户的个人信息")
    public Result<PersonalCenterVO> getPersonalCenterById(@RequestParam("account") String account) {
        log.info("根据账号(account)获取用户的个人信息");
        PersonalCenterVO userInfo = personalCenterService.getPersonalCenterById(account);
        return Result.success(userInfo);
    }

    @PostMapping("/updatePassword")
    @Operation(summary = "修改密码")
    public Result updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO) {
        boolean success = personalCenterService.updatePassword(updatePasswordDTO);
        if(success) {
            return Result.success("密码修改成功");
        } else {
            return Result.error("原密码错误");
        }
    }
}